<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Session;
use DB;
use Mail;

class RetpwdController extends Controller
{
	    /**
	    *   找回密码控制器
	    */
	    public function getRetpwd()
	    {
	        return view('home/retpwd/retpwd');
	    }

	    /** 
	    *	找回密码
	    */
	   public function getDoretpwd()
	   {
	   		$pwdname = $_GET['pwdname'];  //获取用户名

	   		$vcode = $_GET['vcode'];  //获取验证码

	   		//判断验证码
	   		if(Session::get('vcode') != $vcode) return 5;

	   		$res = DB::table('project_user')->where('username',$pwdname)->first();

	   		//将id存入session
	   		Session()->set('id',$res->id);

	   		if(!$res) {

	   			return 6;
	   		} else {

	   			return 7;
	   		}
	   }


	   /**
	   *	输入邮箱
	   */
	   public function getEmails()
	   {
	   		//获取id
	   		$id = session()->get('id');
	   		return view('home/retpwd/emails',['id'=>$id]);
	   }

	   /**
	   *	验证邮箱
	   */
	   public function postMyemail(Request $request)
	   {
	   		$id = $request->input('id');
	   		$email = $request->input('email');

	   		$toke = DB::table('project_user')->where('id',$id)->first();
	   	
	   		$res = DB::table('project_user_details')->where('uid',$id)->first();
	   		// dd($email);
	   		if($email != $res->email){
	   			return back()->with("error","注册邮箱不存在");
	   		}

	   		//发邮件
	   		Mail::send('home/retpwd.remails',['id'=>$id,'token'=>$toke->token], function ($m) use ($res) {
          
            $m->from('wjsshine1234@sina.com','sunshine');      //自己的邮箱  固定的

            $m->to($res->email)->subject('逆战网!');      //用户邮箱
       		 });


	   		return view('/home/retpwd/prompt');

	   }

	   public function getFind()
	   {
	   		echo 111;
	   }


      
















}
